* lisp/imenu.el: Fix multiple inheritance breakage.
authorStefan Monnier <monnier@iro.umontreal.ca>
Thu, 15 Mar 2012 01:38:40 +0000 (21:38 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Thu, 15 Mar 2012 01:38:40 +0000 (21:38 -0400)
(imenu-add-to-menubar): Don't add a redundant index.
(imenu-update-menubar): Handle a dynamically composed keymap.

lisp/ChangeLog
lisp/imenu.el

index 9db48bc89ac88a9c6abb2b8082988ec796304019..c48e5dd24c422668df90bb8c3ab0d2f2b1f7bf57 100644 (file)
@@ -1,3 +1,9 @@
+2012-03-15  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+       * imenu.el: Fix multiple inheritance breakage (bug#9199).
+       (imenu-add-to-menubar): Don't add a redundant index.
+       (imenu-update-menubar): Handle a dynamically composed keymap.
+
 2012-03-13  Katsumi Yamaoka  <yamaoka@jpl.org>
 
        * mail/sendmail.el (mail-encode-header):
index 9a847f32e8983b250c2c911da45713ca1c1c92c0..8363956355b863396470b39803309730f5e61946 100644 (file)
@@ -963,13 +963,14 @@ See the command `imenu' for more information."
          imenu-generic-expression
          (not (eq imenu-create-index-function
                   'imenu-default-create-index-function)))
-      (let ((newmap (make-sparse-keymap)))
-       (set-keymap-parent newmap (current-local-map))
-       (setq imenu--last-menubar-index-alist nil)
-       (define-key newmap [menu-bar index]
-         `(menu-item ,name ,(make-sparse-keymap "Imenu")))
-       (use-local-map newmap)
-       (add-hook 'menu-bar-update-hook 'imenu-update-menubar))
+      (unless (keymapp (lookup-key (current-local-map) [menu-bar index]))
+       (let ((newmap (make-sparse-keymap)))
+         (set-keymap-parent newmap (current-local-map))
+         (setq imenu--last-menubar-index-alist nil)
+         (define-key newmap [menu-bar index]
+           `(menu-item ,name ,(make-sparse-keymap "Imenu")))
+         (use-local-map newmap)
+         (add-hook 'menu-bar-update-hook 'imenu-update-menubar)))
     (error "The mode `%s' does not support Imenu"
            (format-mode-line mode-name))))
 
@@ -1008,6 +1009,9 @@ to `imenu-update-menubar'.")
                                                   (car (cdr menu))))
                                            'imenu--menubar-select))
          (setq old (lookup-key (current-local-map) [menu-bar index]))
+         ;; This should never happen, but in some odd cases, potentially,
+         ;; lookup-key may return a dynamically composed keymap.
+         (if (keymapp (cadr old)) (setq old (cadr old)))
          (setcdr old (cdr menu1)))))))
 
 (defun imenu--menubar-select (item)